package com.tjtt.tdm.system.action;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.tjtt.common.utils.StringUtil;

/**
 * 
 */
public class ShowTree {
	//生成左边菜单
	public static String createLeftMenu1(String module,HttpServletRequest request){
		StringBuffer tree = new StringBuffer();
		List list = (List)request.getSession().getAttribute("MENU_INFO");
		 String srcUrl = "";
		if(list.size()>0){
			int j = 0;
			for(int i=0;i<list.size();i++){
				HashMap module1 = (HashMap)list.get(i);
				String menuid = String.valueOf(module1.get("MENUID"));
				String menuname = (String)module1.get("MENUNAME");
				String parentid = String.valueOf(module1.get("PARENTID"));
				String url = (String)module1.get("URL");
				if(parentid.equals(module)){//如果父节点对
					if(StringUtil.isNull(url)){
		     			srcUrl = request.getContextPath() +"/right.htm";
		     		}else{
		     			if(url.startsWith("/")){
		     				srcUrl = request.getContextPath() + url;
		     			}else{
		     				srcUrl = request.getContextPath()+ "/" + url;
		     			}
		     			  if(srcUrl.indexOf('?')==-1){
			    	    		srcUrl = srcUrl + "?menuModuleId=" + menuid + "&query=true";
			    	    	}else{
			    	    		srcUrl = srcUrl + "&menuModuleId=" + menuid + "&query=true";
			    	    	}
		     		}
					tree.append("<div  tip=\""+menuid+"\" id=\"menudiv"+String.valueOf(j+1)+"\" class=\"shiyunlei2\"" +
							" onclick=\"zhedie('shiyunul"+String.valueOf(j+1)+"',this);parent.mainFrame.document.location.href='"+srcUrl+"'\">" +
									"<p>"+menuname+"</p></div>");
					 if(list.size()>0){
				        	tree.append("<ul id=\"shiyunul"+String.valueOf(j+1)+"\" class=\"shiyunul\">");
				        	for(int m=0;m<list.size();m++){
								HashMap modulem = (HashMap)list.get(m);
								String menuidm = String.valueOf(modulem.get("MENUID"));
								String menunamem = (String)modulem.get("MENUNAME");
								String parentidm = String.valueOf(modulem.get("PARENTID"));
								String urlm = (String)modulem.get("URL");
								if(parentidm.equals(menuid)){
									if(StringUtil.isNull(urlm)){
						     			srcUrl = request.getContextPath() +"/right.htm";
						     		}else{
						     			if(srcUrl.startsWith("/")){
						     				srcUrl = request.getContextPath() + urlm;
						     			}else{
						     				srcUrl = request.getContextPath()+ "/" + urlm;
						     			}
						     			  if(srcUrl.indexOf('?')==-1){
							    	    		srcUrl = srcUrl + "?menuModuleId=" + menuidm + "&query=true";
							    	    	}else{
							    	    		srcUrl = srcUrl + "&menuModuleId=" + menuidm + "&query=true";
							    	    	}
						     		}
						     		 tree.append("<li tip=\""+menuidm+"\" onclick=\"changeBgColor('shiyunul"+String.valueOf(j+1)+"',this)\" ><IMG src=\"../images/fangdian_06.gif\" align=\"middle\" />&nbsp;<a href=\"#\" onclick=\"javascript:parent.mainFrame.document.location.href='"+srcUrl+"'\">"+menunamem+"</a></li>");
						        
								}
				        	}
				        	tree.append("</ul>");
				        }else{
				        	tree.append("<ul id=\"shiyunul"+String.valueOf(j+1)+"\" class=\"shiyunul\">");
				        	tree.append("</ul>");
				        }
					 j++;
				}
			}
			 
		}
        return tree.toString();
	}
	//生成常用菜单 无锡TDM 用到
	public static String createLeftMenu(String module,HttpServletRequest request){
		StringBuffer tree = new StringBuffer();
		List list = (List)request.getSession().getAttribute("OFTEN_MENU_INFO");
		 String srcUrl = "";
		if(list.size()>0){
			tree.append("<div id=\"menudiv99\" class=\"shiyunlei2\" onclick=\"zhedie3('shiyunul99',this)\"><p>常用菜单</p></div>");
			tree.append("<ul id=\"shiyunul99\" class=\"shiyunul\">");
			for(int i=0;i<list.size();i++){
				HashMap module1 = (HashMap)list.get(i);
				String id = String.valueOf(module1.get("ID"));
				String menuid = String.valueOf(module1.get("MENUID"));
				String menuname = (String)module1.get("MENUNAME");
				String parentid = String.valueOf(module1.get("PARENTID"));
				String url = (String)module1.get("URL");
		     		if(StringUtil.isNull(url)){
		     			srcUrl = request.getContextPath() +"/right.htm";
		     		}else{
		     			if(url.startsWith("/")){
		     				srcUrl = request.getContextPath() + url;
		     			}else{
		     				srcUrl = request.getContextPath()+ "/" + url;
		     			}
		     			  if(srcUrl.indexOf('?')==-1){
			    	    		srcUrl = srcUrl + "?menuModuleId=" + menuid + "&query=true";
			    	    	}else{
			    	    		srcUrl = srcUrl + "&menuModuleId=" + menuid + "&query=true";
			    	    	}
		     		}
		     		 tree.append("<li tip=\""+menuid+"\" menuid=\""+id+"\" flag=\"del\" onclick=\"changeBgColor('shiyunul99',this)\" ><IMG src=\"../images/fangdian_06.gif\" align=\"middle\" />&nbsp;<a href=\"#\" onclick=\"javascript:parent.mainFrame.document.location.href='"+srcUrl+"'\">"+menuname+"</a></li>");
	        }
			tree.append("</ul>");
		}
        return tree.toString();
	}
	/**
	 * 兴平TDM菜单生成
	 * @param request
	 * @return String
	 * @author 李数
	 * @date 2013-1-28 下午03:23:00
	 */
	public static String createXpMenu(HttpServletRequest request){
		StringBuffer tree = new StringBuffer();
		List list = (List)request.getSession().getAttribute("MENU_INFO");
		String srcUrl = "";
		if(null!=list&&list.size()>0){
			int j = 0;
			for(int i=0;i<list.size();i++){
				HashMap module1 = (HashMap)list.get(i);
				String parentid = String.valueOf(module1.get("PARENTID"));
				if(!parentid.equals("1")){//如果是第一层节点
					HashMap modulem = (HashMap)list.get(i);
					String menunamem = (String)modulem.get("MENUNAME");
					String urlm = (String)modulem.get("URL");
					if(StringUtil.isNull(urlm)){
		     			srcUrl = request.getContextPath() +"/right.htm";
		     		}else{
		     			if(urlm.startsWith("/")){
		     				srcUrl = request.getContextPath() + urlm;
		     			}else{
		     				srcUrl = request.getContextPath()+ "/" + urlm;
		     			}
		     		}
		     		tree.append("<li><a href=\"javascript:;\"  onclick=\"changeRight('"+srcUrl+"','"+menunamem+"')\"  >"+ menunamem +"</a></li>");
				}
			}
			 
		}
        return tree.toString();
	}
}
